﻿@using Abp.Collections.Extensions
@using AbpCompanyName.AbpProjectName.Web.Views
@using AbpCompanyName.AbpProjectName.Web.Views.Shared.Components.SideBarNav
@model SideBarNavViewModel
@{
    var calculateMenuUrl = new Func<string, string>((url) =>
    {
        if (string.IsNullOrEmpty(url))
        {
            return ApplicationPath;
        }

        if (UrlChecker.IsRooted(url))
        {
            return url;
        }

        return ApplicationPath + url;
    });
}
<div class="menu">
    <ul class="list">
        @foreach (var menuItem in Model.MainMenu.Items)
        {
            <li class="@(Model.ActiveMenuItemName == menuItem.Name ? "active" : "")">
                @if (menuItem.Items.IsNullOrEmpty())
                {
                    <a href="@calculateMenuUrl(menuItem.Url)">
                        @if (!string.IsNullOrWhiteSpace(menuItem.Icon))
                        {
                            <i class="material-icons">@menuItem.Icon</i>
                        }
                        <span>@menuItem.DisplayName</span>
                    </a>
                }
                else
                {
                    <a href="javascript:void(0);" class="menu-toggle">
                        @if (!string.IsNullOrWhiteSpace(menuItem.Icon))
                        {
                            <i class="material-icons">@menuItem.Icon</i>
                        }
                        <span>@menuItem.DisplayName</span>
                    </a>
                    <ul class="ml-menu">
                        @foreach (var subMenuItem in menuItem.Items)
                        {
                            <li class="@(Model.ActiveMenuItemName == subMenuItem.Name ? "active" : "")">
                                @if (subMenuItem.Items.IsNullOrEmpty())
                                {
                                    <a href="@calculateMenuUrl(subMenuItem.Url)">
                                        @if (!string.IsNullOrWhiteSpace(subMenuItem.Icon))
                                        {
                                            <i class="material-icons">@subMenuItem.Icon</i>
                                        }
                                        <span>@subMenuItem.DisplayName</span>
                                    </a>
                                }
                                else
                                {
                                    <a href="javascript:void(0);" class="menu-toggle">
                                        @if (!string.IsNullOrWhiteSpace(subMenuItem.Icon))
                                        {
                                            <i class="material-icons">@subMenuItem.Icon</i>
                                        }
                                        <span>@subMenuItem.DisplayName</span>
                                    </a>
                                    <ul class="ml-menu">
                                        @foreach (var subSubMenuItem in subMenuItem.Items)
                                        {
                                            <li class="@(Model.ActiveMenuItemName == subSubMenuItem.Name ? "active" : "")">
                                                <a href="@calculateMenuUrl(subSubMenuItem.Url)">
                                                    @subSubMenuItem.DisplayName
                                                </a>
                                            </li>
                                        }
                                    </ul>
                                }
                            </li>
                        }
                    </ul>
                }
            </li>
        }
    </ul>
</div>
